package org.sample.core;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;

/**
 * @author: madasamy
 * @version: 0.0
 */
public class CollectionService
{

    private DB db;

    public CollectionService(DB db)
    {
        this.db = db;
    }

    //Create collection
   public void create(BasicDBObject basicDBObject, String collectionName)
    {
        DBCollection collection = db.getCollection(collectionName);
        collection.insert(basicDBObject);
    }

    //Find all collection from given collection name
    public DBCursor findAll(String collectionName)
    {
        return db.getCollection(collectionName).find();
    }

    //Find by given basicdbobject query
    public DBCursor find(BasicDBObject basicDBObject, String collectionName)
    {
        DBCollection collection = db.getCollection(collectionName);
        return collection.find(basicDBObject);
    }

    //
    public void update(BasicDBObject queryObject, BasicDBObject updateObject, String book)
    {
        DBCollection collection = db.getCollection(book);
        collection.update(queryObject, updateObject);

    }

    //delete collection from database.
    public void drop(String book)
    {
        DBCollection collection = db.getCollection(book);
        collection.drop();
    }
}
